
package io.xiyou.user.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.xiyou.core.bloom.BloomFilterHelper;
import io.xiyou.core.bloom.RedisBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName：ProducerController
 * @Author：西柚
 * @Date：2021/10/28 6:05 下午
 * @Versiion：1.0
 */
@RestController
public class BloomController {

    @Autowired
    RedisBloomFilter redisBloomFilter;

    @Autowired
    private BloomFilterHelper bloomFilterHelper;

    @GetMapping("/add")
    @ApiImplicitParam(name = "orderNum", value = "订单号", required = true, dataType = "String", paramType = "query")
    public String addBloomFilter(@RequestParam("orderNum") String orderNum) {
        try {
            redisBloomFilter.addByBloomFilter(bloomFilterHelper, "bloom", orderNum);
        } catch (Exception e) {
            e.printStackTrace();
            return "添加失败";
        }

        return "添加成功";
    }

    @GetMapping("/check")
    @ApiImplicitParam(name = "orderNum", value = "订单号", required = true, dataType = "String", paramType = "query")
    public boolean checkBloomFilter(@RequestParam("orderNum") String orderNum) {
        boolean b = redisBloomFilter.includeByBloomFilter(bloomFilterHelper, "bloom", orderNum);

        return b;
    }

}
